package chapter5;

/**
 * An object of class PairOfDice represents a pair of dice,
 * where each die shows a number between 1 and 6.  The dice
 * can be rolled, which randomizes the numbers showing on the
 * dice.
 */

public class PairOfDice {

   private int die1;   // Number showing on the first die.
   private int die2;   // Number showing on the second die.

   /**
    * Constructor creates a pair of dice and rolls them so that
    * they initially show some random value.
    */
   public PairOfDice() {
       roll();  // Call the roll() method to roll the dice.
   }
   
   /**
    * Roll the dice by setting each die to be a random number between 1 and 6.
    */
   public void roll() {
       die1 = (int)(Math.random()*6) + 1;
       die2 = (int)(Math.random()*6) + 1;
   }
           
   /**
    * Return the number showing on the first die.
    */ 
   public int getDie1() {
      return die1;
   }
   
   /**
    * Return the number showing on the second die.
    */ 
   public int getDie2() {
      return die2;
   }
   
   /**
    * Return the total showing on the two dice.
    */ 
   public int getTotal() {
      return die1 + die2;
   }
   
}  // end class PairOfDice
